package com.finna.user.service.impl;

import com.finna.user.entity.UserInfo;
import com.finna.user.mapper.UserInfoMapper;
import com.finna.user.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class UserInfoServiceImpl implements UserInfoService {
    
    @Autowired
    private UserInfoMapper userInfoMapper;
    
    @Override
    public UserInfo createUserInfo(UserInfo userInfo) {
        userInfo.setCreateTime(LocalDateTime.now());
        userInfo.setUpdateTime(LocalDateTime.now());
        userInfo.setDeleted(false);
        userInfoMapper.insert(userInfo);
        return userInfo;
    }
    
    @Override
    public UserInfo updateUserInfo(UserInfo userInfo) {
        userInfo.setUpdateTime(LocalDateTime.now());
        userInfoMapper.updateById(userInfo);
        return userInfo;
    }
    
    @Override
    public boolean deleteUserInfo(Long userId) {
        return userInfoMapper.deleteById(userId) > 0;
    }
    
    @Override
    public UserInfo getUserInfo(Long userId) {
        return userInfoMapper.selectById(userId);
    }
    
    @Override
    public List<UserInfo> listUserInfo() {
        return userInfoMapper.selectList();
    }
}